package com.guoguo.tangyan.controller;

import com.guoguo.tangyan.entity.Order;
import com.guoguo.tangyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 第一种方式：pazu控件
     * 只支持ie浏览器
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/order/pazu/print")
    public String pazuPrint(Model model, @RequestParam(required = false, defaultValue = "0") Long id) {
        Order order = orderService.getOrder(id);
        model.addAttribute("order", order);
        if (order == null) {
            return "success";
        }
        return "order-print-pazu";
    }

    /**
     * 第二种方式：lodop控件
     * 几乎支持所有 windows 浏览器
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/order/lodop/print")
    public String lodopPrint(Model model, @RequestParam(required = false, defaultValue = "0") Long id) {
        Order order = orderService.getOrder(id);
        model.addAttribute("order", order);
        if (order == null) {
            return "success";
        }
        return "order-print-lodop";
    }
}
